import request from '@/utils/request'

export function rewriteRequest(data) {
  return request({
    url: '/api/request',
    method: 'post',
    data: {
      params: {},
      ...data,
      headers: {
        cookie: document.cookie,
        ...(data.headers || {})
      }
    }
  })
}

export function loginTemuSys(data) {
  return request({
    url: '/api/loginTemu',
    method: 'post',
    data
  })
}

/**
 * 获取cookie
 * @returns {*}
 */
export function getCookie() {
  return request({
    url: '/api/getCookies',
    method: 'post'
  })
}

/**
 * cookie有效状态 { status: 1 不可用 | 0 可用 }
 * @returns {*}
 */
export function checkCookieStatus() {
  return request({
    url: '/api/getCookieStatus',
    method: 'post'
  })
}

/**
 * 抢仓 old
 * @returns {*}
 */
export function batchRob(data) {
  return request({
    url: '/api/batchRob',
    method: 'post',
    data
  })
}

/**
 * 抢仓
 * @param mallId_list
 * @returns {*}
 */
export function starRob(mallId_list) {
  return request({
    url: '/api/startRob',
    method: 'post',
    data: { mallId_list }
  })
}

/**
 * 停止抢仓
 * @returns {*}
 */
export function stopRob() {
  return request({
    url: '/api/stopRob',
    method: 'post'
  })
}

/**
 * 获取店铺的备货单
 * @param mallId
 * @returns {*}
 */
export function getRobOrderList(mallId) {
  return request({
    url: '/api/getSubOrderInfo',
    method: 'post',
    data: { mallId }
  })
}

/**
 * 抢仓状态
 * {"status":0,"mallId_list":[]},status为0代表没有抢仓，status为1代表正在抢仓
 * @returns {*}
 */
export function robState() {
  return request({
    url: '/api/getRobStatus',
    method: 'post'
  })
}

/**
 * 店铺销售数据
 * @param data
 * @returns {*}
 */
export function getSaleData(data) {
  return request({
    url: '/api/getShopInfoList ',
    method: 'post',
    data
  })
}

/**
 * 获取抢仓配置
 * @returns {*}
 */
export function getRobConfig() {
  return request({
    url: '/api/getCreateDeliveryOrdersConfig',
    method: 'post'
  })
}

/**
 * 设置抢仓配置
 * @param data
 * {
 *    "is_need_create":true,
 *    "is_create_by_max_num":false
 *  }
 * @returns {*}
 */
export function setRobConfig(data) {
  return request({
    url: '/api/setCreateDeliveryOrdersConfig',
    method: 'post',
    data
  })
}

/**
 * 设置抢仓项的属性
 * @param data
 * @returns {*}
 */
export function setRobItemStatus(data) {
  return request({
    url: '/api/setRobItemStatus',
    method: 'post',
    data
  })
}

/**
 * 获取抢仓项的属性
 * @param data
 * @returns {*}
 */
export function getRobItemStatus(data) {
  return request({
    url: '/api/queryRobItemStatus',
    method: 'post',
    data
  })
}

/**
 * 查询发货仓库信息
 * @param mallId
 * @returns {*}
 */
export function queryDeliveryAddressInfo(mallId) {
  return request({
    url: '/api/queryDeliveryAddressInfo',
    method: 'post',
    data: { mallId }
  })
}

/**
 * 设置备货单发货地址信息
 * @param data
 * @returns {*}
 */
export function setRobItemDeliveryAddressId(data) {
  return request({
    url: '/api/setRobItemDeliveryAddressId',
    method: 'post',
    data
  })
}

/**
 * 查询已经设置的备货单的发货地址信息
 * @param mallId
 * @param robIdList
 * @returns {*}
 */
export function queryRobItemDeliveryAddressId(mallId, robIdList) {
  return request({
    url: '/api/queryRobItemDeliveryAddressId',
    method: 'post',
    data: { mallId, robIdList }
  })
}

export function heartBeats() {
  return request({
    url: '/api/sendHeartBeat',
    method: 'get'
  })
}

export function saveServCookie(serv_cookies) {
  return request({
    url: '/api/setServCookies',
    method: 'post',
    data: {
      serv_cookies
    }
  })
}

export function getServCookie() {
  return request({
    url: '/api/getServCookies',
    method: 'get'
  })
}
